__author__ = 'jiangjun'
__date__ = '2018/4/16 下午7:40'

import json
import os


class FileUtils:

    @classmethod
    def get_value(cls, file_name):
        f = None
        try:
            if not os.path.exists(file_name):
                return None
            f = open(file_name, encoding='utf-8', mode='r')
            if f:
                data = f.read()
                data_json = json.loads(data)
                return data_json
            else:
                return None
        except Exception as e:
            print('读文件异常异常信息：%s' % e)
        finally:
            if f:
                f.close()

    @classmethod
    def set_value(cls, file_name, json_content):
        f = None
        try:
            # if not os.path.exists(file_name):
            #     return None
            f = open(file_name, encoding='utf-8', mode='w')
            f.writelines(json_content)
        except Exception as e:
            print('写文件异常异常信息：%s' % e)
        finally:
            if f:
                f.close()

